<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* G6 (https://github.com/antvis/G6)
*********************************************************************-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title data-i18n="resources.title_l7_path_map"></title>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <style>
      body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100vh;
        overflow: hidden;
      }
      #map {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>

  <body>
    <div id="map"></div>
    <script type="text/javascript" include="L7,maplibre-gl-enhance" src="../../dist/maplibregl/include-maplibregl.js"></script>
    <script type="text/javascript">
      var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
      var attribution =
        "<a href='https://maplibre.org/' target='_blank'>© MapLibre </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
        " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

      var tileURL = host + '/iserver/services/map-china/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}';
      var map = new maplibregl.Map({
        container: 'map',
        style: {
          version: 8,
          sources: {
            'raster-tiles': {
              attribution: attribution,
              type: 'raster',
              tiles: [tileURL],
              tileSize: 256
            }
          },
          layers: [
            {
              id: 'simple-tiles',
              type: 'raster',
              source: 'raster-tiles',
              minzoom: 0,
              maxzoom: 22
            }
          ]
        },
        center: [120.15, 30.246],
        zoom: 13.5
        // pitchEnable: false,
      });

      map.on('load', function () {
        map.getL7Scene().then((scene) => {
          scene.addImage('arrow', '../img/ce83fc30-701f-415b-9750-4b146f4b3dd6.svg');
          fetch('https://iclient.supermap.io/web/data/L7/67130c6c-7f49-4680-915c-54e69730861d.json')
            .then((data) => data.json())
            .then(({ lakeBorderData, lakeData, landData }) => {
              var lakeLayer = new maplibregl.supermap.L7Layer({ type: 'PolygonLayer' });
              lakeLayer
                .getL7Layer()
                .source(lakeData)
                .shape('fill')
                .color('#1E90FF')
                .style({
                  opacity: 0.4,
                  opacityLinear: {
                    enable: true,
                    dir: 'out' // in - out
                  }
                });
              var landLayer = new maplibregl.supermap.L7Layer({ type: 'PolygonLayer' });
              landLayer
                .getL7Layer()
                .source(landData)
                .shape('fill')
                .color('#3CB371')
                .style({
                  opacity: 0.4,
                  opacityLinear: {
                    enable: true,
                    dir: 'in' // in - out
                  }
                });

              var lakeBorderLayer = new maplibregl.supermap.L7Layer({ type: 'PolygonLayer' });
              lakeBorderLayer
                .getL7Layer()
                .source(lakeBorderData)
                .shape('fill')
                .color('#ccc')
                .style({
                  opacity: 0.5,
                  opacityLinear: {
                    enable: true,
                    dir: 'in' // in - out
                  }
                });

              map.addLayer(lakeLayer);
              map.addLayer(lakeBorderLayer);
              map.addLayer(landLayer);
            });
          fetch('https://iclient.supermap.io/web/data/L7/40ef2173-df66-4154-a8c0-785e93a5f18e.json')
            .then((res) => res.json())
            .then((data) => {
              var layer = new maplibregl.supermap.L7Layer({ type: 'LineLayer' });
              layer
                .getL7Layer()
                .source(data)
                .size(3)
                .shape('line')
                .texture('arrow')
                .color('rgb(22,119,255)')
                .animate({
                  interval: 1, // 间隔
                  duration: 1, // 持续时间，延时
                  trailLength: 2 // 流线长度
                })
                .style({
                  opacity: 0.6,
                  lineTexture: true, // 开启线的贴图功能
                  iconStep: 10, // 设置贴图纹理的间距
                  borderWidth: 0.4, // 默认文 0，最大有效值为 0.5
                  borderColor: '#fff' // 默认为 #ccc
                });
              map.addLayer(layer);
            });
        });
      });
    </script>
  </body>
</html>
